package com.hkj.configcenter.core;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.github.zkclient.ZkClient;
import com.hkj.configcenter.core.model.FieldInfo;
import com.hkj.configcenter.core.model.ProjectConfig;
import com.hkj.configcenter.core.model.StringComparator;

public class Context {

    public static boolean switchOn = false;

    public static final String ONLINE_MACHINES = "/online-machines";

    public static final String SPLIT_FLAG = "#-#";

    public static final String LINE_FEED = "#=#";

    public static final StringComparator STRING_COMPARATOR = new StringComparator();

    private static ProjectConfig config;

    public static ZkClient zkClient;

    private static Map<String, List<FieldInfo>> fieldInfoCache = new HashMap<>();

    private static Map<String, String> fieldParamCache = new HashMap<String, String>();

    public static boolean isSwitchOn() {
        return switchOn;
    }

    public static void setSwitchOn(boolean switchOn) {
        Context.switchOn = switchOn;
    }

    public static Map<String, String> getField_PathValue() {
        return fieldParamCache;
    }

    public static Map<String, List<FieldInfo>> getFieldInfoCache() {
        return fieldInfoCache;
    }

    public static String getZkUrl() {
        return config.getZkUrl();
    }

    public static String getConfigRootPath() {
        return config == null ? "/config" : config.getRoot();
    }

    public static String getConfigEnvPath() {
        return getConfigRootPath() + config.getEnv();
    }

    public static String getOnlineMachinesPath() {
        return config.getOnlineMachinesPath();
    }

    public static String getCommonConfig() {
        return config.getCommonConfig();
    }

    public static String getCommonConfigPath() {
        return config.getCommonConfigPath();
    }

    public static String getFieldConfigPath() {
        return config.getFieldConfigPath();
    }

    public static String getResourceConfigPath() {
        return config.getResourceConfigPath();
    }

    public static ProjectConfig getConfig() {
        return config;
    }

    public static void setConfig(ProjectConfig config) {
        Context.config = config;
    }

}
